﻿#region Using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.Entity;
#endregion // Using

namespace Mvp.Library.Entities.Context
{
    public class MvpContext : DbContext
    {
        #region Constructors
        /**********************************************************************
         * Constructors
         *********************************************************************/
        public MvpContext(IContextInfo contextInfo = null)
        {
            if (contextInfo == null) { contextInfo = new ContextInfo(); }
            this.SetContextInfo(contextInfo);
        }// of constructor(IContextInfo)
        #endregion // Constructors

        #region Business Methods
        /**********************************************************************
         * Business Methods
         *********************************************************************/
        internal void SetContextInfo(IContextInfo contextInfo)
        {
            if (contextInfo != null)
            {
                if (contextInfo is IContextInfo<MvpContext>)
                {
                    IContextInfo<MvpContext> mvpCtxInfo = contextInfo as IContextInfo<MvpContext>;
                    if (mvpCtxInfo.DbInitializer != null)
                    {
                        Database.SetInitializer<MvpContext>(mvpCtxInfo.DbInitializer);
                    }// if the initializer is set
                }// if this is the right type
            } // if the context info is set
        }// of SetContextInfo(IContextInfo)
        #endregion // Business Methods

        #region Tables
        /**********************************************************************
         * Tables
         *********************************************************************/
        public DbSet<Configuration> Configurations { get; set; }
        public DbSet<ConfigurationSetting> ConfigurationSettings { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Announcement> Announcements { get; set; }
        public DbSet<ContactUsItem> ContactUsItems { get; set; }
        public DbSet<RealEstateItem> RealEstateItems { get; set; }
        #endregion // Tables

        #region Factory Methods
        /**********************************************************************
         * Factory Methods
         *********************************************************************/
        #endregion // Factory Methods
    }// of class MvpContext
}// of namespace Mvp.Library.Entities